home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / files.swg / 0073_Hiding Files.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-05-26  |  4.4 KB  |  105 lines

  1. {
  2. Here are some routines for Hiding files, making read only files and
  3. stuff.  Let me know what you think.  Any comments, criticism, or rude
  4. remarks are welcome.
  5.  
  6. { *********************** Files Unit *********************** }
  7. { **************** Written by: Rick Haines ***************** }
  8. { ***************** Last Revised 02/02/95 ****************** }
  9.  
  10. Unit Files;
  11.  
  12. Interface
  13.  
  14.  { Note: All FileNames MUST end in a null Char }
  15.  { EX:   HideFile(FileName+#0);                }
  16.  { EX:   HideFile('MyFile.Exe'+#0);            }
  17.  
  18.  Function HideFile(FileName : String) : Byte;     { Hide FileName }
  19.  Function SystemFile(FileName : String) : Byte;   { Make FileName a System File}
  20.  Function ReadOnlyFile(FileName : String) : Byte; { Make FileName ReadOnly     }
  21.  Function NormalFile(FileName : String) : Byte;   { Make FileName a Normal File}
  22.  Function FileAttributes(FileName : String) : Integer; { Returns Attributes of }
  23.  
  24. Implementation
  25.  
  26.  Function HideFile(FileName : String) : Byte; Assembler;
  27.   Asm
  28.    Push DS           { Push Data Segment                  }
  29.    LDS DX, FileName  { Nul Terminated String of FileName  }
  30.    Inc DX            { Get Rid Of Length Byte             }
  31.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  32.    Mov AL, 1         { Change Attributes                  }
  33.    Mov CX, 2         { Bit 1, Hide It                     }
  34.    Int 21h           { Call Dos                           }
  35.    JC @Done          { See if there was an error          }
  36.    Mov AL, 0         { If Not, Then No Error              }
  37.   @Done:
  38.    Pop DS            { Pop Data Segment                   }
  39.   End;
  40.  
  41.  Function SystemFile(FileName : String) : Byte; Assembler;
  42.   Asm
  43.    Push DS           { Push Data Segment                  }
  44.    LDS DX, FileName  { Nul Terminated String of FileName  }
  45.    Inc DX            { Get Rid Of Length Byte             }
  46.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  47.    Mov AL, 1         { Change Attributes                  }
  48.    Mov CX, 4         { Bit 3, System File                 }
  49.    Int 21h           { Call Dos                           }
  50.    JC @Done          { See if there was an error          }
  51.    Mov AL, 0         { If Not, Then No Error              }
  52.   @Done:
  53.    Pop DS            { Pop Data Segment                   }
  54.   End;
  55.  
  56.  Function ReadOnlyFile(FileName : String) : Byte; Assembler;
  57.   Asm
  58.    Push DS           { Push Data Segment                  }
  59.    LDS DX, FileName  { Nul Terminated String of FileName  }
  60.    Inc DX            { Get Rid Of Length Byte             }
  61.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  62.    Mov AL, 1         { Change Attributes                  }
  63.    Mov CX, 1         { Bit 0, Read Only                   }
  64.    Int 21h           { Call Dos                           }
  65.    JC @Done          { See if there was an error          }
  66.    Mov AL, 0         { If Not, Then No Error              }
  67.   @Done:
  68.    Pop DS            { Pop Data Segment                   }
  69.   End;
  70.  
  71.  Function NormalFile(FileName : String) : Byte; Assembler;
  72.   Asm
  73.    Push DS           { Push Data Segment                  }
  74.    LDS DX, FileName  { Nul Terminated String of FileName  }
  75.    Inc DX            { Get Rid of Length Byte             }
  76.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  77.    Mov AL, 1         { Change Attributes                  }
  78.    Mov CX, 0         { Nothing, UnEverything it           }
  79.    Int 21h           { Call Dos                           }
  80.    JC @Done          { See if there was an error          }
  81.    Mov AL, 0         { If not, then no error              }
  82.   @Done:
  83.    Pop DS            { Pop Data Segment                   }
  84.   End;
  85.  
  86.  Function FileAttributes(FileName : String) : Integer; Assembler;
  87.   Asm
  88.    Push DS           { Push Data Segment                  }
  89.    LDS DX, FileName  { Nul Terminated String of FileName  }
  90.    Inc DX            { Get Rid of Length Byte             }
  91.    Mov AH, 43h       { Dos Function 43h, File Change Mode }
  92.    Mov AL, 0         { Return Attributes                  }
  93.    Int 21h           { Call Dos                           }
  94.    JC @Error         { See if there was an error          }
  95.    Mov AX, CX        { Return Attributes                  }
  96.    Jmp @Done
  97.   @Error:
  98.    Mov AX, -1        { Return -1 For Error                }
  99.   @Done:
  100.    Pop DS            { Pop Data Segment                   }
  101.   End;
  102.  
  103. End.
  104.  
  105.